package com.huike.clues.service.impl;


import com.github.pagehelper.PageHelper;
import com.huike.clues.domain.TbClue;
import com.huike.clues.domain.TbClueTrackRecord;
import com.huike.clues.domain.vo.ClueTrackRecordVo;
import com.huike.clues.mapper.TbClueMapper;
import com.huike.clues.mapper.TbClueTrackRecordMapper;
import com.huike.clues.service.ITbClueTrackRecordService;
import com.huike.common.core.domain.BaseEntity;
import com.huike.common.utils.SecurityUtils;
import com.huike.common.utils.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.sound.sampled.TargetDataLine;
import java.util.Date;
import java.util.List;

/**
 * 线索跟进记录Service业务层处理
 *
 * @date 2022-04-22
 */
@Service
public class TbClueTrackRecordServiceImpl implements ITbClueTrackRecordService {

    @Autowired
    TbClueTrackRecordMapper tbClueTrackRecordMapper;
    @Autowired
    TbClueMapper tbClueMapper;

    /**
     * 添加跟进记录
     *
     * @param tbClueTrackRecord
     */
    @Override
    public void addById(ClueTrackRecordVo tbClueTrackRecord) {
        //把ClueTrackRecordVo里的数据拷贝到TbClueTrackRecord里
        TbClueTrackRecord tbClueTrackRecord1 = new TbClueTrackRecord();
        BeanUtils.copyProperties(tbClueTrackRecord, tbClueTrackRecord1);
        //对必填字段进行赋值
        tbClueTrackRecord1.setClueId(tbClueTrackRecord.getClueId());
        tbClueTrackRecord1.setLevel(tbClueTrackRecord.getLevel());
        tbClueTrackRecord1.setSubject(tbClueTrackRecord.getSubject());
        tbClueTrackRecord1.setNextTime(tbClueTrackRecord.getNextTime());

        //创建时间
        tbClueTrackRecord1.setCreateTime(new Date());
        //获取用户
        tbClueTrackRecord1.setCreateBy(SecurityUtils.getUsername());
        tbClueTrackRecordMapper.addById(tbClueTrackRecord1);


        //对客户表获取客户id和name等..赋值到线索表
        TbClue tbClue = new TbClue();
        tbClue.setId(tbClueTrackRecord.getClueId());
        tbClue.setName(tbClueTrackRecord.getName());
        tbClue.setAge(tbClueTrackRecord.getAge());
        tbClue.setWeixin(tbClueTrackRecord.getWeixin());
        tbClue.setQq(tbClueTrackRecord.getQq());
        tbClueMapper.updateTbClue(tbClue);

    }

    /**
     * 查询线索跟进记录
     *
     * @param clueId
     * @return
     */
    @Override
    public List<TbClueTrackRecord> selectClues(Long clueId) {


    /*    TbClueTrackRecord tbClueTrackRecord = new TbClueTrackRecord();
        ClueTrackRecordVo clueTrackRecordVo = new ClueTrackRecordVo();
        BeanUtils.copyProperties(tbClueTrackRecord, clueTrackRecordVo);
        tbClueTrackRecord.setCreateTime(new Date());
        tbClueTrackRecord.setCreateBy(SecurityUtils.getUsername());

        tbClueTrackRecord.setLevel(clueTrackRecordVo.getLevel());
        tbClueTrackRecord.setSubject(clueTrackRecordVo.getSubject());
        tbClueTrackRecord.setRecord(clueTrackRecordVo.getRecord());
        tbClueTrackRecord.setNextTime(clueTrackRecordVo.getNextTime());
*/
        return tbClueTrackRecordMapper.selectTrack(clueId);

    }
}
